<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .div1 {
            width: 400px;
            height: 400px;
            background-color: cornflowerblue;
        }
        .div2{
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="div1">
        <div class="div2"></div>
    </div>
   <script>
    // 要获取的元素是相当于谁定位，获取上级定位元素
    // 每一个元素  如果没有上级定位元素，就是相对于body定位
    console.log(document.querySelector('.div2').offsetParent);
    console.log(document.querySelector('.div2').offsetLeft);
    console.log(document.querySelector('.div2').offsetTop);
   </script>
</body>

</html>